﻿using System;

using Microsoft.Xna.Framework.Graphics;

namespace HorrorsOfArkham.Game_Application_Layer
{
    public class XnaServiceProvider : IServiceProvider, IGraphicsDeviceService
    {
        #region Members

        private readonly GraphicsDevice _graphicsDevice;

        public GraphicsDevice GraphicsDevice
        {
            get { return _graphicsDevice; }
        }

        #endregion

        #region Initialization

        public XnaServiceProvider(GraphicsDevice graphicsDevice)
        {
            try
            {
                _graphicsDevice = graphicsDevice;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        #endregion

        #region Event Handlers

        public event EventHandler<EventArgs> DeviceReset
        {
            add
            {
                _graphicsDevice.DeviceReset += value;
            }
            remove
            {
                _graphicsDevice.DeviceReset -= value;
            }
        }

        public event EventHandler<EventArgs> DeviceResetting
        {
            add
            {
                _graphicsDevice.DeviceResetting += value;
            }
            remove
            {
                _graphicsDevice.DeviceResetting -= value;
            }
        }

        public event EventHandler<EventArgs> DeviceCreated
        {
            add
            {
            }
            remove
            {
            }
        }

        public event EventHandler<EventArgs> DeviceDisposing
        {
            add
            {
                _graphicsDevice.Disposing += value;
            }
            remove
            {
                _graphicsDevice.Disposing -= value;
            }
        }

        #endregion

        #region Other Methods

        public object GetService(Type serviceType)
        {
            return this;
        }

        #endregion
    }
}
